#include "../../../xcom/xall.hpp"

int main(int argc, char* argv[])
{
    const char* ip = argv[1];
    port_t port = atoi(argv[2]);
    
    xsock s;
    bool ret = s.tcp_create();
    X_CHECK(ret,-1);

    ret = s.reuse_addr(1);
    X_CHECK(ret,-1);

    ret = s.reuse_port(1);
    X_CHECK(ret,-1);

    ret = s.xbind(ip,port);
    X_CHECK(ret,-1);

    ret = s.xlisten();
    X_CHECK(ret,-1);
    printf("ok\n");
    while (1)
    {
        xsock c;
        c.sock_ = s.xaccept();
        sockaddr_in peer = c.get_peer_addr();
        printf("acc peer=%s\n",get_addr_str(&peer).c_str());
        auto ret = c.sendto("xxxx",4);
        printf("send ret = %u\n",ret);

        sleep_ns((uint64_t)2*X_NS_IN_SEC);
        ret = c.sendto("xxxx",4);
        printf("send ret = %u\n",ret);
    }
    return 0;
}